package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.api.model.UserShop;
import com.ruoyi.system.domain.BaseShop;
import com.ruoyi.system.domain.dto.ShopDto;
import com.ruoyi.system.domain.vo.ShopVo;
import com.ruoyi.system.mapper.BaseShopMapper;
import com.ruoyi.system.service.IBaseShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2022-09-29
 */
@Service
public class BaseShopServiceImpl implements IBaseShopService
{
    @Autowired
    private BaseShopMapper baseShopMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param shopId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public BaseShop selectBaseShopByShopId(Long shopId)
    {
        return baseShopMapper.selectBaseShopByShopId(shopId);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param baseShop 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<BaseShop> selectBaseShopList(BaseShop baseShop)
    {
        return baseShopMapper.selectBaseShopList(baseShop);
    }

    @Override
    public List<ShopVo> selectShopList(ShopDto baseShop) {
        return baseShopMapper.selectShopList(baseShop);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param baseShop 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertBaseShop(ShopDto baseShop)
    {
        return baseShopMapper.insertBaseShop(baseShop);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param baseShop 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateBaseShop(BaseShop baseShop)
    {
        return baseShopMapper.updateBaseShop(baseShop);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param shopIds 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteBaseShopByShopIds(Long[] shopIds)
    {
        return baseShopMapper.deleteBaseShopByShopIds(shopIds);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param shopId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteBaseShopByShopId(Long shopId)
    {
        return baseShopMapper.deleteBaseShopByShopId(shopId);
    }

    @Override
    public Set<String> selectAllShopCodes() {
        return baseShopMapper.selectAllShopCodes();
    }

    @Override
    public List<ShopVo> selectShopListByUserId(Long userId) {
        return baseShopMapper.selectShopListByUserId(userId);
    }

    @Override
    public List<ShopVo> selectAllShopList() {
        return baseShopMapper.selectAllShopList();
    }

    @Override
    public Set<UserShop> selectAllShops() {
        Set<ShopDto> shops =  baseShopMapper.selectAllShops();
        Set<UserShop> re = new HashSet<>();
        for (ShopDto d:shops) {
            re.add(d.toUserShop());
        }
        return re;
    }

    @Override
    public Set<UserShop> getUserShopsByUserId(Long userId) {
        Set<ShopDto> shops =  baseShopMapper.selectUserShopsByUserId(userId);
        Set<UserShop> re = new HashSet<>();
        for (ShopDto d:shops) {
            re.add(d.toUserShop());
        }
        return re;
    }

    @Override
    public UserShop getUserShopsByShopCode(String shopCode) {
        List<ShopVo> shops =  baseShopMapper.selectUserShopsByShopCode(shopCode);
        UserShop re = null;
        if(StringUtils.isNotNull(shops) && shops.size() > 0)
            re = shops.get(0).toUserShop();
        return re;
    }
}
